import { makePersistedAdapter } from '@livestore/adapter-web'
import LiveStoreSharedWorker from '@livestore/adapter-web/shared-worker?sharedworker'
import { getStore } from '@livestore/solid'
import { Logger, LogLevel } from '@livestore/utils/effect'

import LiveStoreWorker from './livestore/livestore.worker.ts?worker'
import { schema } from './livestore/schema.ts'

// ---cut---

const adapter = makePersistedAdapter({
  storage: { type: 'opfs' },
  worker: LiveStoreWorker,
  sharedWorker: LiveStoreSharedWorker,
})

const _store = await getStore({
  schema,
  adapter,
  storeId: 'default',
  // Optional: swap logger and minimum log level
  logger: Logger.prettyWithThread('window'),
  logLevel: LogLevel.Info, // use LogLevel.None to disable logs
})
